home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / views.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  6.2 KB  |  133 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. from app import db
  19. import feed
  20. import folder
  21. import downloader
  22. import guide
  23. import item
  24. import tabs
  25. import playlist
  26. import searchengines
  27. import theme
  28.  
  29. import indexes
  30. import filters
  31. import maps
  32. import sorts
  33.  
  34. from threading import Condition
  35. initialized = False
  36.     
  37. def initialize():
  38.     global initialized
  39.     initialized = True
  40.     global allTabs, guideTabs, staticTabs, feedTabs, playlistTabs
  41.     global selectedTabs, tabOrders, channelTabOrder, playlistTabOrder
  42.     global items, fileItems, toplevelItems, nonContainerItems, unwatchedItems
  43.     global watchableItems, newWatchableItems, feeds, remoteDownloads
  44.     global httpauths, staticTabsObjects, autoUploads, guides, default_guide
  45.     global manualFeed, singleFeed, directoryFeed, newlyDownloadedItems
  46.     global downloadingItems, pausedItems, manualDownloads, autoDownloads
  47.     global playlists, playlistFolders, channelFolders, searchEngines
  48.     global themeHistories
  49.  
  50.     db.createIndex(indexes.objectsByClass)
  51.  
  52.     allTabs = db.filter(filters.mappableToTab).map(maps.mapToTab)
  53.     allTabs.createIndex(indexes.tabType)
  54.     guideTabs = allTabs.filterWithIndex(indexes.tabType, 'guide') \
  55.                 .sort(sorts.guideTabs)
  56.     staticTabs = allTabs.filterWithIndex(indexes.tabType, 'statictab') \
  57.                  .sort(sorts.staticTabs)
  58.  
  59.     # no need to sort channel/playlist tabs...  These get ordered by the TabOrder
  60.     # class.
  61.     feedTabs = allTabs.filterWithIndex(indexes.tabType, 'feed')
  62.     playlistTabs = allTabs.filterWithIndex(indexes.tabType, 'playlist')
  63.     selectedTabs = allTabs.filter(lambda x: x.selected)
  64.  
  65.     tabOrders = db.filterWithIndex(indexes.objectsByClass, tabs.TabOrder)
  66.     tabOrders.createIndex(indexes.tabOrderType)
  67.     channelTabOrder = tabOrders.filterWithIndex(indexes.tabOrderType, u'channel')
  68.     playlistTabOrder = tabOrders.filterWithIndex(indexes.tabOrderType, u'playlist')
  69.  
  70.     # items includes fileItems.
  71.     items = db.filterWithIndex(indexes.objectsByClass,item.Item)
  72.     fileItems = db.filter(lambda x: isinstance(x, item.FileItem))
  73.     toplevelItems = items.filter(lambda x: x.feed_id is not None)
  74.     nonContainerItems = items.filter(lambda x: not x.isContainerItem)
  75.     unwatchedItems = nonContainerItems.filter(filters.unwatchedItems)
  76.     #expiringItems = nonContainerItems.filter(filters.expiringItems)
  77.     watchableItems = nonContainerItems.filter(filters.watchableItems)
  78.     newWatchableItems = nonContainerItems.filter(filters.newWatchableItems)
  79.  
  80.     # NOTE: we can't use the objectsByClass index for fileItems, because it
  81.     # agregates all Item subclasses into one group.
  82.     feeds = db.filterWithIndex(indexes.objectsByClass,feed.Feed)
  83.     remoteDownloads = db.filterWithIndex(indexes.objectsByClass, downloader.RemoteDownloader)
  84.     httpauths = db.filterWithIndex(indexes.objectsByClass,downloader.HTTPAuthPassword)
  85.     staticTabsObjects = db.filterWithIndex(indexes.objectsByClass,tabs.StaticTab)
  86.  
  87.     remoteDownloads.createIndex(indexes.downloadsByDLID)
  88.     remoteDownloads.createIndex(indexes.downloadsByURL)
  89.     autoUploads = remoteDownloads.filter (filters.autoUploadingDownloaders, sortFunc=sorts.downloadersByEndTime)
  90.     items.createIndex(indexes.itemsByFeed, sortFunc=sorts.item)
  91.     toplevelItems.createIndex(indexes.itemsByFeed)
  92.     items.createIndex(indexes.itemsByParent)
  93.     items.createIndex(indexes.itemsByChannelFolder, sortFunc=sorts.item)
  94.     feeds.createIndex(indexes.feedsByURL)
  95.     feeds.createIndex(indexes.byFolder)
  96.  
  97.     #FIXME: These should just be globals
  98.     guides = db.filterWithIndex(indexes.objectsByClass,guide.ChannelGuide)
  99.     guides.createIndex(indexes.guidesByURL)
  100.     default_guide = guides.filter(lambda x: x.getDefault())
  101.     manualFeed = feeds.filterWithIndex(indexes.feedsByURL, 'dtv:manualFeed')
  102.     singleFeed = feeds.filterWithIndex(indexes.feedsByURL, 'dtv:singleFeed')
  103.     directoryFeed = feeds.filterWithIndex(indexes.feedsByURL,
  104.                                           'dtv:directoryfeed')
  105.  
  106.     items.createIndex(indexes.itemsByState)
  107.     newlyDownloadedItems = items.filterWithIndex(indexes.itemsByState,
  108.                                                  'newly-downloaded')
  109.     downloadingItems = items.filterWithIndex(indexes.itemsByState,
  110.                                              'downloading')
  111.     pausedItems = items.filterWithIndex(indexes.itemsByState, 'paused')
  112.     downloadingItems.createIndex(indexes.downloadsByCategory)
  113.     manualDownloads = items.filter(filters.manualDownloads)
  114.     autoDownloads = items.filter(filters.autoDownloads)
  115.  
  116.     playlists = db.filterWithIndex(indexes.objectsByClass,
  117.                                    playlist.SavedPlaylist)
  118.     playlists.createIndex(indexes.playlistsByItemID, multiValued=True)
  119.     playlists.createIndex(indexes.playlistsByItemAndFolderID, multiValued=True)
  120.     playlists.createIndex(indexes.byFolder)
  121.     playlistFolders = db.filterWithIndex(indexes.objectsByClass,
  122.                                          folder.PlaylistFolder)
  123.     playlistFolders.createIndex(indexes.playlistsByItemID, multiValued=True)
  124.  
  125.     channelFolders = db.filterWithIndex(indexes.objectsByClass,
  126.                                         folder.ChannelFolder)
  127.     channelFolders.createIndex(indexes.foldersByTitle)
  128.     searchEngines = db.filterWithIndex(indexes.objectsByClass,
  129.                                        searchengines.SearchEngine)
  130.     searchEngines = searchEngines.sort(sorts.searchEngines)
  131.  
  132.     themeHistories = db.filterWithIndex(indexes.objectsByClass,theme.ThemeHistory)
  133.